/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.deployment.manager.relatorios;

import br.com.deployment.entidade.acesso.Usuario;
import br.com.deployment.entidade.selo.Distribuicao;
import br.com.deployment.entidade.selo.Selo;
import br.com.deployment.entidade.selo.TipoSelo;
import br.com.deployment.message.Msg;
import br.com.deployment.servico.SeloServico;
import br.com.deployment.servico.TipoSeloServico;
import br.com.deployment.servico.UsuarioServico;
import java.io.Serializable;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.primefaces.event.SelectEvent;

/**
 *
 * @author roniere
 */
@ManagedBean
@ViewScoped
public class ManagerRelatorioSelo implements Serializable{
    @EJB
    SeloServico seloServico;
    @EJB
    UsuarioServico  usuarioServico;
    @EJB
    TipoSeloServico tipoSeloServico;
    
    private Selo selo;
    private Integer numIni;
    private Integer numFim;
    private Distribuicao distribuicao;
    private Date dataIni;
    private Date dataFim;
    
    @PostConstruct
    public void init(){
        selo = new Selo();
        distribuicao = new Distribuicao();
    }

    public Date getDataFim() {
        return dataFim;
    }

    public void setDataFim(Date dataFim) {
        this.dataFim = dataFim;
    }

    public Date getDataIni() {
        return dataIni;
    }

    public void setDataIni(Date dataIni) {
        this.dataIni = dataIni;
    }

    public Distribuicao getDistribuicao() {
        return distribuicao;
    }

    public void setDistribuicao(Distribuicao distribuicao) {
        this.distribuicao = distribuicao;
    }
    
     

    public Integer getNumFim() {
        return numFim;
    }

    public void setNumFim(Integer numFim) {
        this.numFim = numFim;
    }

    public Integer getNumIni() {
        return numIni;
    }

    public void setNumIni(Integer numIni) {
        this.numIni = numIni;
    }
    

    public Selo getSelo() {
        return selo;
    }

    public void setSelo(Selo selo) {
        this.selo = selo;
    }
    
    public void relatorio(){
        seloServico.seloNaoUsado(selo, selo.getTipoSelo(), dataIni, dataFim, distribuicao, numIni, numFim);
        Msg.messagemInfo("Relatório gerado com sucesso !");
    }
    
     public void handleSelect(SelectEvent event) {
        Usuario usuario = (Usuario) event.getObject();
        distribuicao.setRecebedor(usuarioServico.find(usuario.getId()));
    }
     public void handleSelectTipo(SelectEvent event) {
        TipoSelo ts = (TipoSelo) event.getObject();
       selo.setTipoSelo(tipoSeloServico.find(ts.getId()));
    }
    
}
